package com.yy.service.impl;

import com.yy.dao.GoodsDao;
import com.yy.dao.UserDao;
import com.yy.pojo.Goods;
import com.yy.pojo.ShoppingCart;
import com.yy.service.GoodsService;
import com.yy.vo.Shopping;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GoodsServiceImpl implements GoodsService {
    @Autowired
    private GoodsDao goodsDao;
    @Override
    public List<Goods> getAllGoods() {
        return goodsDao.getAllGoods();
    }
    @Override
    public List<Goods> getGoodsByConditon(String condition) {

        return goodsDao.getGoodsByConditon(condition);
    }

    @Override
    public Goods getGoodsDetails(String gid) {
        return goodsDao.getGoodsDetails(gid);
    }

    @Override
    public boolean addShoppingCart(String gid, String num) {
        return goodsDao.addShoppingCart(gid,num);
    }

    @Override
    public List<Shopping> getShoppingCart() {
        List<Shopping> shoppingList = goodsDao.getShoppingCart();
        for (Shopping shopping : shoppingList) {
            shopping.setTotal(shopping.getPrice()*shopping.getCount());
        }
        return shoppingList;
    }
}
